package cn.wolfcode.luowowo.mgrsite.controller;


import cn.wolfcode.luowowo.acticle.domain.StrategyDetail;
import cn.wolfcode.luowowo.acticle.query.StrategyDetailQuery;
import cn.wolfcode.luowowo.acticle.service.*;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyDetail")
public class StrategyDetailController {
    @Reference(retries = -1)
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IStrategyService strategyService;
    @Reference
    private IStrategyThemeService strategyThemeService;
    @Reference
    private IStrategyCatalogService strategyCatalogService;
    @Reference
    private IRegionService regionService;
    @Reference
    private IStrategyContentService strategyContentService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")StrategyDetailQuery qo){
        model.addAttribute("pageInfo", strategyDetailService.query(qo));
        return "strategyDetail/list";
    }

    @RequestMapping("/input")
    public String input(Model model, Long id){
        if(id != null){

            StrategyDetail strategyDetail = strategyDetailService.get(id);
            strategyDetail.setStrategyContent(strategyContentService.get(id));
            model.addAttribute("strategyDetail", strategyDetail);

            model.addAttribute("tags",strategyDetailService.getTags(id));
        }
        //攻略主题
        model.addAttribute("themes", strategyThemeService.list());
        //攻略
        model.addAttribute("strategies", strategyService.list());
        //目的地, 需要根据攻略关联游记决定
        return "strategyDetail/input";
    }

    @RequestMapping("/getCatalogByStrategyId")
    @ResponseBody
    public Object getCatalogByStrategyId(Long strategyId){
        return strategyCatalogService.getCatalogByStrategyId(strategyId);
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object input(StrategyDetail strategyDetail, String tags){
        strategyDetailService.saveOrUpdate(strategyDetail,tags);
        return new AjaxResult();
    }

    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(Long id, int state){
        strategyDetailService.changeState(id, state);
        return new AjaxResult();
    }






}
